<?php
header('Content-type:text/html;charset=utf8');
$config = [
    'host' => '127.0.0.1',
    'user' => 'root',
    'password' => 'root',
    'database' => 'php8_rainy',
    'charset' => 'utf8'
];
$dsn = sprintf("mysql:host=%s;dbname=%s;charset=%s"
    , $config['host'], $config['database'], $config['charset']);

try {
    $pdo = new PDO($dsn, $config['user'], $config['password']);
    $pdo->exec("INSERT INTO news (title, author, remark) VALUES('php8', 'hyper', 'PHP是世界上最好的语言')");
    // 获取最后一次插入的id
    echo $pdo->lastInsertId();
} catch (PDOException $e) {
    echo $e->getMessage();
}
